//
//  JWCalendarSettingHelper.m
//  SiqiCalendar
//
//  Created by sunjiawen on 2018/4/10.
//  Copyright © 2018年 sjw. All rights reserved.
//

#import "JWCalendarSettingHelper.h"
#import "JWCalendarModel.h"
#import "JWRealmManager.h"

@implementation JWCalendarSettingHelper

static JWCalendarSettingHelper *_helper = nil;

+ (instancetype)sharedInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _helper = [[JWCalendarSettingHelper alloc]init];
    });
    return _helper;
}

- (void)setupCalendarModel:(JWCalendarModel *)calendar {
    
    self.pendingCalendarModel = nil;
    self.pendingCalendarModel = [JWCalendarModel modelWithCalendarModel:calendar];
    
}

- (void)setupInitialCalendarModel {
    
    self.pendingCalendarModel = nil;
    self.pendingCalendarModel = [[JWCalendarModel alloc]init];
}

- (void)updateCalendarName:(NSString *)calendarName {
    self.pendingCalendarModel.calendarName = calendarName;
}

- (void)updateCalendarSchedule:(RLMArray *)schedules {
    self.pendingCalendarModel.scheduleStatus = schedules;
}

- (void)updateCalendarOrderIndex:(NSNumber *)orderIndex isDefault:(NSNumber *)isDefault firstDate:(NSDate *)firstDate {
    self.pendingCalendarModel.orderIndex = orderIndex;
    self.pendingCalendarModel.isDefault = isDefault;
    self.pendingCalendarModel.firstDate = firstDate;
}

- (void)confirmEdit {
    [self updateRealmData];
}

/**
 更新数据库中的内容
 */
- (void)updateRealmData {
    [[JWRealmManager defaultManager] addOrUpdateWithJWCalendarModel:self.pendingCalendarModel];
}
@end
